//
//  ForgetPWRetypePasswordController.m
//  HuLaQuan
//
//  Created by hok on 1/21/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "ForgetPWRetypePasswordController.h"

#import "ForgetUserPasswordEngine.h"

@interface ForgetPWRetypePasswordController ()

@property (nonatomic, strong) ForgetUserPasswordEngine *forgetUserPasswordEngine;

@end

@implementation ForgetPWRetypePasswordController

- (ForgetUserPasswordEngine *)forgetUserPasswordEngine
{
    if (!_forgetUserPasswordEngine) {
        _forgetUserPasswordEngine = [[ForgetUserPasswordEngine alloc] init];
    }
    return _forgetUserPasswordEngine;
}
-(NSString *)finish:(NSString *)pwd{
     NSLog(@"%@ %@" ,pwd,self.passwordAndInfos);
    if([pwd isEqualToString:self.passwordAndInfos[@"password"]])
    {
        [YuNetworkStatusUtilities showProgressMessage:NETWORK_LOADING];
        [self.forgetUserPasswordEngine resetUserPasswordWithName:self.passwordAndInfos[@"userName"] andPassword:self.passwordAndInfos[@"password"] andToken:self.passwordAndInfos[@"tokenValue"]];
    }else{
        [self.view makeToast:kPasswordRetypeNotEqual];
    }
    return pwd;
    
}
#pragma mark - CallBack
- (void)resetUserPasswordFinish:(NSNotification*) notification
{
    [YuNetworkStatusUtilities dismissHUD];
    NSDictionary *messageDic = [notification object];//获取到传递的对象
    if ([messageDic[@"isSuccess"] boolValue]) {
        
        UIAlertController *x = [UIAlertController alertWithTitle:@"提示" andMessage:@"重置登录密码成功" andBlock:^(UIAlertAction *action ) {
            if ([action.title isEqualToString:@"好的"]) {
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
            
        }  type:@"confirm"];
        [self presentViewController:x animated:YES completion:nil]; 
        
    }else{
        [self showNetWorkError:messageDic[@"message"]];
        
    }
    
}
#pragma mark - Controller Life Cycle
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetUserPasswordFinish:) name:@"ResetUserPasswordFinish" object:nil];

    
}

- (void)viewWillDisappear:(BOOL)animated
{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ResetUserPasswordFinish" object:nil];

    [super viewWillDisappear:YES];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Navigation
- (void)goBackAction
{
    UIAlertController *x = [UIAlertController alertWithTitle:@"提示" andMessage:@"是否放弃重置登录密码" andBlock:^(UIAlertAction *action ) {
        if ([action.title isEqualToString:@"好的"]) {
            [self.navigationController popToRootViewControllerAnimated:YES];
            [[UIApplication sharedApplication].keyWindow endEditing:YES];
        }
        
    }  type:@"confirmAndCancel"];
    [self presentViewController:x animated:YES completion:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
